package client.domain.ui.northPanel;

import static client.domain.SandboxMainKeys.*;
import client.internationalization.SandboxConstants;
import client.internationalization.SandboxMessages;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Image;
import com.gwtext.client.core.Position;
import com.gwtext.client.core.RegionPosition;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.form.FormPanel;
import com.gwtext.client.widgets.form.TextField;
import com.gwtext.client.widgets.form.VType;
import com.gwtext.client.widgets.layout.*;

/**
 * User: nbarrios
 * Date: Nov 9, 2009
 */
public class NorthPanel extends Panel {

	//	Internationalization Strings
	private SandboxConstants constants = GWT.create(SandboxConstants.class);
	private SandboxMessages messages = GWT.create(SandboxMessages.class);

	private BorderLayoutData northData;

	private Button registerButton = new Button(constants.register());

	// Constructor
	public NorthPanel() {
		this.setHeight(100);
		this.setMargins(0,100,100,0);
		this.setStyleName("northPanel");
		this.setCollapsible(true);
		this.setLayout(new HorizontalLayout(0));

		northData = new BorderLayoutData(RegionPosition.NORTH);
		northData.setSplit(true);
		northData.setAnimFloat(true);


		//	Add the widgets

		//	Create the FormPanel and set the label position to top
		FormPanel formPanel = new FormPanel();
		formPanel.setFrame(true);
		formPanel.setPaddings(2, 2, 2, 0);
		formPanel.setWidth(700);
		formPanel.setLabelAlign(Position.LEFT);

		//create top panel with ColumnLayout
		Panel topPanel = new Panel();
		topPanel.setLayout(new ColumnLayout());

		//create first panel and add fields to it
		Panel columnOnePanel = new Panel();
		columnOnePanel.setLayout(new FormLayout());

		TextField firstName = new TextField(constants.firstName(), "first");
		firstName.setTabIndex(0);
		columnOnePanel.add(firstName, new AnchorLayoutData("80%"));

		TextField company = new TextField(constants.company(), "company");
		company.setTabIndex(2);
		columnOnePanel.add(company, new AnchorLayoutData("80%"));

		//add first panel as first column with 50% of the width
		topPanel.add(columnOnePanel, new ColumnLayoutData(.5));         
				

		//create second panel and add fields to it
		Panel columnTwoPanel = new Panel();
		columnTwoPanel.setLayout(new FormLayout());

		TextField lastName = new TextField(constants.lastName(), "last");
		lastName.setTabIndex(1);
		columnTwoPanel.add(lastName, new AnchorLayoutData("90%"));

		TextField email = new TextField(constants.email(), "email");
		email.setTabIndex(3);
		email.setVtype(VType.EMAIL);
		columnTwoPanel.add(email, new AnchorLayoutData("90%"));

		//add the second panel as the second column to the top panel to take up the other 50% width
		topPanel.add(columnTwoPanel, new ColumnLayoutData(0.5));
		formPanel.add(topPanel);

		//add a couple of buttons to the form
		registerButton.setTabIndex(4);
		formPanel.addButton(registerButton);
		formPanel.addButton(new Button(constants.cancel()));


		//	Add the Kaitzen Logo
		Image kaitzenLogo = new Image(IMG_KAITZEN_LOGO);
		kaitzenLogo.setSize(NORTH_PANEL_HEIGHT_ST, NORTH_PANEL_HEIGHT_ST);



		this.add(formPanel);
		this.add(kaitzenLogo);
	}

	//  Getters & Setters
	public BorderLayoutData getNorthData() {
		return northData;
	}

	public void setNorthData(BorderLayoutData northData) {
		this.northData = northData;
	}
}
